import 'package:floor/floor.dart';

@entity
class Book {

  Book({
    required this.isbn,
    required this.bookName,
    required this.author,
    required this.press,
    required this.pressDate,
    required this.pressPlace,
    required this.price,
    required this.pictures,
    required this.clcCode,
    required this.clcName,
    required this.bookDesc,
    required this.binding,
    required this.language,
    required this.format,
    required this.pages,
    required this.edition,
    required this.words,
  });

  @primaryKey
  String isbn;
  String bookName;
  String author;
  String press;
  String pressDate;
  String pressPlace;
  double price;
  String pictures;
  String clcCode;
  String clcName;
  String bookDesc;
  String binding;
  String language;
  String format;
  String pages;
  String edition;
  String words;

  factory Book.fromJson(Map<String, dynamic> json) => Book(
    isbn: json['isbn'] as String,
    bookName: json['bookName'] as String,
    author: json['author'] as String,
    press: json['press'] as String,
    pressDate: json['pressDate'] as String,
    pressPlace: json['pressPlace'] as String,
    price: (json['price'] as num).toDouble(),
    pictures: json['pictures'] as String,
    clcCode: json['clcCode'] as String,
    clcName: json['clcName'] as String,
    bookDesc: json['bookDesc'] as String,
    binding: json['binding'] as String,
    language: json['language'] as String,
    format: json['format'] as String,
    pages: json['pages'] as String,
    edition: json['edition'] as String,
    words: json['words'] as String,
  );

  Map<String, dynamic> toJson() => {
    'isbn': isbn,
    'bookName': bookName,
    'author': author,
    'press': press,
    'pressDate': pressDate,
    'pressPlace': pressPlace,
    'price': price,
    'pictures': pictures,
    'clcCode': clcCode,
    'clcName': clcName,
    'bookDesc': bookDesc,
    'binding': binding,
    'language': language,
    'format': format,
    'pages': pages,
    'edition': edition,
    'words': words,
  };

}
